﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExpertMIS.Brokers;
using System.Collections;
using ExpertMIS.Entities;
using System.Text;

namespace ExpertMIS.Forums.UserControl
{
    public partial class ucUserInfo : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        private void LoadReplyInfo(string UserOID)
        {
            ucSearchResult1.SearchByReply(UserOID, string.Empty);
        }

        public void LoadExpertInfo(string ExpertOID)
        {
            ExpertBroker expertBroker = new ExpertBroker();

            Hashtable htKeys = new Hashtable();
            htKeys.Add("OID", ExpertOID);

            ExpertEntity expert = expertBroker.GetEntity(htKeys) as ExpertEntity;

            lblName.Text = expert.Name;
            hlEMail.Text = string.Format("<a href='mailto:{0}'>{0}</a>", expert.EMail);
            lblBirthday.Text = expert.Birthday;
            lblPhone.Text = string.Format("{0}{2}{1}", expert.Phone, expert.CellPhone, string.IsNullOrEmpty(expert.Phone) || string.IsNullOrEmpty(expert.CellPhone)?"":",");
            lblPosition.Text = string.Format("{0}{2}{1}", expert.AdminPosition, expert.Skills, string.IsNullOrEmpty(expert.AdminPosition)|| string.IsNullOrEmpty(expert.Skills)?"":"、");
            lblMajor.Text = expert.Expertise;

            lblAward.Text = ExpertMIS.Codes.Utility.ReplaceNLC2BR(expert.Awards);

            ADMUserBroker userBroker = new ADMUserBroker();
            htKeys["OID"] = expert.UserID;
            ADMUserEntity user = userBroker.GetEntity(htKeys) as ADMUserEntity;
            if (user != null)
            {
                LoadReplyInfo(user.OID);
            }

            StringBuilder sb = new StringBuilder();
            foreach (DomainEntity domain in expertBroker.GetExpertDomains(expert.OID))
            {
                if (sb.Length > 0) sb.Append(",");
                sb.Append(string.Format("<a href='DomainIntroduce.aspx?oid={0}' alt=''>{1}</a>", domain.OID, domain.DomainName, domain.Remark));
            }
            lblDomains.Text = sb.ToString();

            AnswerBroker answerBroker = new AnswerBroker();
            int replayCount = answerBroker.GetUserReplyCount(expert.UserID);
            int appectCount = answerBroker.GetUserReplyCount(expert.UserID);
            lblReplyCount.Text = string.Format("{0}", replayCount);
            lblAcceptCount.Text = string.Format("{0}", appectCount);
            lblAcceptRate.Text = string.Format("{0}%", replayCount != 0 ? (appectCount / replayCount) * 100 : 0);
        }
    }
}